const state = () => ({
  data: {
    volunteerInfos: {}, // 志愿表数据
    searchArraylist: [],
    schoolArrayList: [], // 学校
    majorArrayList: [], // 专业
    jobArrayList: [], // 职业
    advancedList: [], // 高级
  },
});

// actions
const actions = {
  // 保存志愿表
  setVolunteerInfos({ commit }, dataInfo) {
    commit('setVolunteerInfos', dataInfo);
  },
  // 整合所有筛选数据
  saveSearchInfoChange({ commit }) {
    // 添加方法
    commit('saveSearchInfoChange');
  },
  // 院校筛选
  saveSchoolInfoChange({ commit }, dataInfo) {
    // 添加方法
    commit('saveSchoolInfoChange', dataInfo);
    commit('saveSearchInfoChange');
  },
  // 专业筛选
  saveMajorInfoChange({ commit }, dataInfo) {
    commit('saveMajorInfoChange', dataInfo);
    commit('saveSearchInfoChange');
  },
  // 职业筛选
  saveJobInfoChange({ commit }, dataInfo) {
    commit('saveJobInfoChange', dataInfo);
    commit('saveSearchInfoChange');
  },
  // 高级筛选
  saveAdvancedInfoChange({ commit }, dataInfo) {
    commit('saveAdvancedInfoChange', dataInfo);
    commit('saveSearchInfoChange');
  },
  delAllSearchInfo({ commit }) {
    commit('delAllSearchInfo');
    commit('saveSearchInfoChange');
  },
};

// mutations
const mutations = {
  setVolunteerInfos: (state, dataInfo) => {
    state.data.volunteerInfos = dataInfo; // 保存来自组件的数据信息
  },
  saveSearchInfoChange: (state) => {
    state.data.searchArraylist = [
      ...state.data.schoolArrayList,
      ...state.data.majorArrayList,
      ...state.data.jobArrayList,
      ...state.data.advancedList,
    ];
  },
  saveSchoolInfoChange: (state, dataInfo) => {
    state.data.schoolArrayList = dataInfo;
  },
  saveMajorInfoChange: (state, dataInfo) => {
    state.data.majorArrayList = dataInfo;
  },
  saveJobInfoChange: (state, dataInfo) => {
    state.data.jobArrayList = dataInfo;
  },
  saveAdvancedInfoChange: (state, dataInfo) => {
    state.data.advancedList = dataInfo;
  },
  delAllSearchInfo: (state) => {
    state.data.schoolArrayList = [];
    state.data.majorArrayList = [];
    state.data.jobArrayList = [];
    state.data.advancedList = [];
  },
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
};
